package web.video;

import bean.Video;
import com.alibaba.fastjson.JSON;
import entity.VideoEntity;
import util.FANREN;

import javax.persistence.EntityManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "VideoPlay",urlPatterns = "/dao/VideoPlay")
public class VideoPlay extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String jsonString = FANREN.getJson(request);
        //播放量views++
        Video video = JSON.parseObject(jsonString,Video.class);
        EntityManager em = (EntityManager) request.getAttribute("_entity.Manager");
        VideoEntity v = em.find(VideoEntity.class,Integer.parseInt(video.getVid()));
        v.setViews((Integer.parseInt(video.getViews())+1)+"");
    }
}
